package com.lm.location.action;


import java.util.ArrayList;
import java.util.List;

import com.lm.location.dao.LocationDao;
import com.opensymphony.xwork2.ActionSupport;

public class AddLocation extends LocationAction{
	
	
	public String addLocation() throws Exception {		
		List<Object> myList = new ArrayList<Object>();
		myList.add("eeeeeeeee");
		myList.add("qqqqqqqqq");
		myList.add("aaaaaaaaa");
		myList.add("ssssssss");
		// get user details
		/*User user = getUser();
		System.out.println("user id save --- "+user.getUserId());
		System.out.println("getName id save --- "+user.getName());
		*/		
		Location location = getLocationDetails();
		
		System.out.println("added location................"+getName());
		//LocationAction loc = new LocationAction();
		
		LocationDao locDao = new LocationDao();
		locDao.saveNewLocation(location);
		
		return SUCCESS;
	}

	public String staList() throws Exception {	
		
		
		List<State> staList = new ArrayList<State>();
		staList = setStaList();
		
		List<String> staNameList = new ArrayList<String>();
		for(int i=0; i< stateList.size(); i++){
			staNameList.add(stateList.get(i).getStanam());
		}
		setStateNameList(staNameList);
		return SUCCESS;
	}
	
	public List<State> setStaList() {	
		System.out.println("searched location................"+getName());
		//Location loc = getLocationDetails();
		LocationDao locDao = new LocationDao();
		List<State> stateList = locDao.getStateList();
		setStateList(stateList);
		
		return stateList;
	}
	
	// to get the district List
		public String dstList() throws Exception {	
		staList();
		setLocationCode(getLocationCode());
		setName(getName());
		setCategory(getCategory());
		setAddress(getAddress());
		setCountry(getCountry());
		setState(getState());
		List<District> dstList = new ArrayList<District>();
		dstList = setDstList();
		
		List<String> dstNameList = new ArrayList<String>();
		for(int i=0; i< districtList.size(); i++){
			dstNameList.add(districtList.get(i).getDstnam());
		}
		setDistrictNameList(dstNameList);
		return SUCCESS;
	}
	
		public List<District> setDstList() {	
			System.out.println("searched location................"+getName());
			LocationDao locDao = new LocationDao();
			List<District> dstList = locDao.getDstList(getState());
			setDistrictList(dstList);
			return dstList;
		}

}
